package com.workcell.workdata.im.component.validator;

import com.workcell.workdata.im.annotation.validator.MomentVideoFormat;
import com.workcell.workdata.im.entity.Moment;
import com.workcell.workdata.im.model.message.CloudVideo;
import com.workcell.workdata.im.model.request.MomentRequest;
import com.workcell.workdata.im.util.JSON;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class MomentVideoValidator implements ConstraintValidator<MomentVideoFormat, MomentRequest> {

    @Override
    public boolean isValid(MomentRequest momentRequest, ConstraintValidatorContext context) {
        if (momentRequest.getType() != Moment.FORMAT_VIDEO){
            return true;
        }
        CloudVideo video = JSON.parseNullable(momentRequest.getContent(), CloudVideo.class);

        return video != null
                && video.getVideo() != null
                && video.getImage() != null
                && video.getBucket() != null;
    }
}
